<?php   
class ControllerCommonHeader extends Controller {
	protected $category_id = 0;
	protected $path = array();
	protected function index() {
    	if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['language_code'])) {
			$this->session->data['language'] = $this->request->post['language_code'];
		
			if (isset($this->request->post['redirect'])) {
				$this->redirect($this->request->post['redirect']);
			} else {
				$this->redirect(HTTP_SERVER . 'index.php?route=common/home');
			}
    	}		
		
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['currency_code'])) {
      		$this->currency->set($this->request->post['currency_code']);
			
			unset($this->session->data['shipping_methods']);
			unset($this->session->data['shipping_method']);
				
			if (isset($this->request->post['redirect'])) {
				$this->redirect($this->request->post['redirect']);
			} else {
				$this->redirect(HTTP_SERVER . 'index.php?route=common/home');
			}
   		}
		
		$this->language->load('common/header');
		
		if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
			$server = HTTPS_IMAGE;
		} else {
			$server = HTTP_IMAGE;
		}
			
		$this->data['title'] = $this->document->title;
		$this->data['keywords'] = $this->document->keywords;
		$this->data['description'] = $this->document->description;
		$this->data['template'] = $this->config->get('config_template');
		
		
		if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
			$this->data['base'] = HTTPS_SERVER;
		} else {
			$this->data['base'] = HTTP_SERVER;
		}
		
		if ($this->config->get('config_icon') && file_exists(DIR_IMAGE . $this->config->get('config_icon'))) {
			$this->data['icon'] = $server . $this->config->get('config_icon');
		} else {
			$this->data['icon'] = '';
		}
		
		$this->data['charset'] = $this->language->get('charset');
		$this->data['lang'] = $this->language->get('code');
		$this->data['direction'] = $this->language->get('direction');
		$this->data['links'] = $this->document->links;	
		$this->data['styles'] = $this->document->styles;
		$this->data['scripts'] = $this->document->scripts;		
		$this->data['breadcrumbs'] = $this->document->breadcrumbs;
		
		$this->data['store'] = $this->config->get('config_name');
		
		if ($this->config->get('config_logo') && file_exists(DIR_IMAGE . $this->config->get('config_logo'))) {
			$this->data['logo'] = $server . $this->config->get('config_logo');
		} else {
			$this->data['logo'] = '';
		}
		
		$this->data['text_home'] = $this->language->get('text_home');
		$this->data['text_special'] = $this->language->get('text_special');
		$this->data['text_contact'] = $this->language->get('text_contact');
		$this->data['text_sitemap'] = $this->language->get('text_sitemap');
		$this->data['text_bookmark'] = $this->language->get('text_bookmark');
    	$this->data['text_account'] = $this->language->get('text_account');
    	$this->data['text_login'] = $this->language->get('text_login');
    	$this->data['text_logout'] = $this->language->get('text_logout');
    	$this->data['text_cart'] = $this->language->get('text_cart'); 
    	$this->data['text_checkout'] = $this->language->get('text_checkout');
		$this->data['text_keyword'] = $this->language->get('text_keyword');
		$this->data['text_category'] = $this->language->get('text_category');
		$this->data['text_advanced'] = $this->language->get('text_advanced');
		$this->data['entry_zone'] = $this->language->get('entry_zone');	
		$this->data['entry_city'] = $this->language->get('entry_city');	
		$this->data['entry_name'] = $this->language->get('entry_name');
		$this->data['entry_search'] = $this->language->get('entry_search');
		$this->data['text_model'] = $this->language->get('text_model');
		$this->data['text_detail'] = $this->language->get('text_detail');
		$this->data['reduced'] = $this->language->get('reduced');
		$this->data['sold'] = $this->language->get('sold');
		$this->data['openbanner'] = $this->language->get('openbanner');
		$this->data['button_go'] = $this->language->get('button_go');
		$this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
		$this->data['home'] = HTTP_SERVER . 'index.php?route=common/home';
		$this->data['special'] = HTTP_SERVER . 'index.php?route=product/special';
		$this->data['contact'] = HTTP_SERVER . 'index.php?route=information/contact';
    	$this->data['sitemap'] = HTTP_SERVER . 'index.php?route=information/sitemap';
    	$this->data['account'] = HTTPS_SERVER . 'index.php?route=account/account';
		$this->data['logged'] = $this->customer->isLogged();
		$this->data['login'] = HTTPS_SERVER . 'index.php?route=account/login';
		$this->data['logout'] = HTTP_SERVER . 'index.php?route=account/logout';
    	$this->data['cart'] = HTTP_SERVER . 'index.php?route=checkout/cart';
		$this->data['checkout'] = HTTPS_SERVER . 'index.php?route=checkout/shipping';
		
		if (isset($this->request->get['keyword'])) {
			$this->data['keyword'] = $this->request->get['keyword'];
		} else {
			$this->data['keyword'] = '';
		}
		
		if (isset($this->request->get['category_id'])) {
			$this->data['category_id'] = $this->request->get['category_id'];
		} elseif (isset($this->request->get['path'])) {
			$path = explode('_', $this->request->get['path']);
		
			$this->data['category_id'] = end($path);
		} else {
			$this->data['category_id'] = '';
		}
		
		$this->data['advanced'] = HTTP_SERVER . 'index.php?route=product/search';
		
		$this->load->model('catalog/category');
		
		$categories = $this->getCategories2(0);
		$this->load->model('catalog/cat');
		$categories2 = $this->getCategories2(0,'','cat');
		$this->data['categories'] = $categories.$categories2;
		
		$this->data['action'] = HTTP_SERVER . 'index.php?route=common/home';

		if (!isset($this->request->get['route'])) {
			$this->data['redirect'] = HTTP_SERVER . 'index.php?route=common/home';
		} else {
			$this->load->model('tool/seo_url');
			
			$data = $this->request->get;
			
			unset($data['_route_']);
			
			$route = $data['route'];
			
			unset($data['route']);
			
			$url = '';
			
			if ($data) {
				$url = '&' . urldecode(http_build_query($data));
			}			
			
			$this->data['redirect'] = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=' . $route . $url);
		}
		
		$this->data['language_code'] = $this->session->data['language'];
		$this->data['telephone'] = $this->config->get('config_telephone');
		$this->load->model('localisation/language');
		
		$this->data['languages'] = array();
		
		$results = $this->model_localisation_language->getLanguages();
		
		foreach ($results as $result) {
			if ($result['status']) {
				$this->data['languages'][] = array(
					'name'  => $result['name'],
					'code'  => $result['code'],
					'image' => $result['image']
				);	
			}
		}
		
		$this->data['currency_code'] = $this->currency->getCode(); 
		
		$this->load->model('localisation/currency');
		 
		 $this->data['currencies'] = array();
		 
		$results = $this->model_localisation_currency->getCurrencies();	
		
		foreach ($results as $result) {
			if ($result['status']) {
   				$this->data['currencies'][] = array(
					'title' => $result['title'],
					'code'  => $result['code']
				);
			}
		}
		$this->language->load('module/featured');		
		$this->load->model('catalog/product');
		$this->load->model('catalog/review');
		$this->load->model('tool/seo_url');
		$this->load->model('tool/image');			
		$this->data['products'] = array();
		
		$results = $this->model_catalog_product->getfeaturedProducts($this->config->get('featured_limit'));
			
		foreach ($results as $result) {
			if ($result['image']) {
				$image = $result['image'];
			} else {
				$image = 'no_image.jpg';
			}
			
			if ($this->config->get('config_review')) {
				$rating = $this->model_catalog_review->getAverageRating($result['product_id']);	
			} else {
				$rating = false;
			}

			$special = FALSE;
			
			$discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
			
			if ($discount) {
				$price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
			} else {
				$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
			
				$special = $this->model_catalog_product->getProductSpecial($result['product_id']);
			
				if ($special) {
					$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
				}						
			}			
			$options = $this->model_catalog_product->getProductOptions($result['product_id']);
			
			if ($options) {
				$add = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']);
			} else {
				$add = HTTPS_SERVER . 'index.php?route=checkout/cart&product_id=' . $result['product_id'];
			}
			$date= date('l d-m-Y', strtotime($result['date_available']));
			$weight_unit=$this->model_catalog_product->getAreaUnit($result['weight_class_id']);
			$area='';
			if($result['weight']!=0){
				$area = $result['weight']." ".$weight_unit;
			}
			$this->data['products'][] = array(
				'product_id'    => $result['product_id'],
				'name'    		=> $result['name'],
				'model'   		=> $result['model'],
				'rating'  		=> $rating,
				'stars'   		=> sprintf($this->language->get('text_stars'), $rating),
				'price'   		=> $price,
				'options'   	=> $options,
				'special' 		=> $special,
				'image'   		=> $this->model_tool_image->resize($image, 436, 300),
				'thumb'   		=> $this->model_tool_image->resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),
				'href'    		=> $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']),
				'area'    		=> $area,
				'zone'			=> $this->model_catalog_product->getZoneName($result['zone_id']),
				'city'			=> $this->model_catalog_product->getCityName($result['city_id']),
				'stock'			=> $this->model_catalog_product->getStockProductStockId($result['stock_status_id']),
				'manufacturer'	=> $this->model_catalog_product->getManufacturer($result['manufacturer_id']),
				'date_available' => $this->translateDate($date),
				'meta_description'=>$result['meta_description']
				
			);
		}
		if (!$this->config->get('config_customer_price')) {
			$this->data['display_price'] = TRUE;
		} elseif ($this->customer->isLogged()) {
			$this->data['display_price'] = TRUE;
		} else {
			$this->data['display_price'] = FALSE;
		}
		$this->language->load('module/information');
		
    	$this->data['infomation_title'] = $this->language->get('heading_title');
		
		$this->load->model('catalog/information');
		$this->load->model('tool/seo_url');
		
		$this->data['informations'] = array();

		foreach ($this->model_catalog_information->getInformations() as $result) {
      		$this->data['informations'][] = array(
        		'title' => $result['title'],
	    		'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=information/information&information_id=' . $result['information_id'])
      		);
    	}

		$this->data['contact'] = HTTP_SERVER . 'index.php?route=information/contact';
    	$this->data['sitemap'] = HTTP_SERVER . 'index.php?route=information/sitemap';
		$this->id = 'header';
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/common/header.tpl';
		} else {
			$this->template = 'default/template/common/header.tpl';
		}
		
    	$this->render();
	}	
	
	private function getCategories($parent_id, $level = 0) {
		$level++;
		
		$data = array();
		
		$results = $this->model_catalog_category->getCategories($parent_id);
		
		foreach ($results as $result) {
			$data[] = array(
				'category_id' => $result['category_id'],
				'name'        => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level) . $result['name']
			);
			
			$children = $this->getCategories($result['category_id'], $level);
			
			if ($children) {
			  $data = array_merge($data, $children);
			}
		}
		
		return $data;
	}
	protected function getCategories2($parent_id, $current_path = '',$category='category') {		
		$category_id = array_shift($this->path);
		
		if($category=='category'){		
			$results = $this->model_catalog_category->getCategories($parent_id);
			$getc='category_id';
			$pathc='category&amp;path=';
		}else{
			$results = $this->model_catalog_cat->getCats($parent_id);
			$getc='cat_id';
			$pathc='cat&amp;paths=';
		}
		$path_active = '';
		static $loop =0;
		$output ='';
		if(isset($this->request->get['path']))
		{
			$path_active = $this->request->get['path'];
				
			if($loop == 0){
				$loop++;
				if(!$path_active){
					$output ='<li class="mega active first"><a href="'.$this->data['home'].'" class="mega active first"><span class="menu-title">'.$this->data['text_home'].'</span></a></li>';
				}else{
					$output ='<li class="mega first"><a href="'.$this->data['home'].'" class="mega  first"><span class="menu-title">'.$this->data['text_home'].'</span></a></li>';
				}
			}else
			{
				$output ='';
			}
		}else if(isset($this->request->get['paths']))
		{
			$path_active = $this->request->get['paths'];
						
			if($loop == 0){
				$loop++;
				if(!$path_active){
					$output ='<li class="mega active first"><a href="'.$this->data['home'].'" class="mega active first"><span class="menu-title">'.$this->data['text_home'].'</span></a></li>';
				}else{
					$output ='<li class="mega first"><a href="'.$this->data['home'].'" class="mega  first"><span class="menu-title">'.$this->data['text_home'].'</span></a></li>';
				}
			}else
			{
				$output ='';
			}
		}
		else
		{	
			if($loop == 0)
			{
				$loop++;
				$output ='<li class="mega active first"><a href="'.$this->data['home'].'" class="mega active first"><span class="menu-title">'.$this->data['text_home'].'</span></a></li>';
			}else
			{
				$output = '';
			}
		}
		foreach ($results as $result) {	
			if ($result) { 
				if($parent_id!=0){
					$output .= '<li class="mega haschild">';
				}else{
					if(isset($this->request->get['path']))
					{
						$path_new = '';
						
						$path_new = $this->request->get['path'];
						$path_new = explode('_',$path_new);
						if($result[$getc] == $path_new[0])
						{
							$output .= '<li class="mega active">';
						}
						else{
							$output .= '<li class="mega">';
						}
					}else if (isset($this->request->get['paths'])){
					$path_new = '';
						
						$path_new = $this->request->get['paths'];
						$path_new = explode('_',$path_new);
						if($result[$getc] == $path_new[0])
						{
							$output .= '<li class="mega active">';
						}
						else{
							$output .= '<li class="mega">';
						}
					}
					else 
					{
						$output .= '<li class="mega ">';
					}
					
				}
    		} 
			if (!$current_path) {
				$new_path = $result[$getc];
			} else {
				$new_path = $current_path . '_' . $result[$getc];
			}
    		$output .= '<a class="mega haschild" href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path)  . '"><span class="menu-title">' . $result['name'] . '</span></a>';  
			$output .= '<div class="childcontent cols1 ">
				<div class="childcontent-inner-wrap">
				<div class="top" ><div class="tl"></div>
				<div class="tr"></div></div>
				<div class="mid">
				<div class="ml"></div>';

			$children = '';
			
			if ($category_id != $result[$getc]) {
				$children = $this->getCategoriesChild($result[$getc], $new_path,$category);
			}
			
			
			
        	$output .= $children;
        
        	$output .= '<div class="mr"></div>
						</div><div class="bot" ><div class="bl"></div><div class="br"></div></div>
						</div></div></li>'; 
		}
 
		
		
		return $output;
	}
	protected function getCategoriesChild($parent_id, $current_path = '',$category='category'){
		$category_id = array_shift($this->path);
		
		//echo($count);	
		$output = '';		
		if($category=='category'){		
			$results = $this->model_catalog_category->getCategories($parent_id);
			$count=$this->model_catalog_category->countLayout($parent_id);
			$check=$this->model_catalog_category->checkChildrenMenu($parent_id);
			$getc='category_id';
			$pathc='category&amp;path=';
		}else{
			$results = $this->model_catalog_cat->getCats($parent_id);
			$count=$this->model_catalog_cat->countLayout($parent_id);
			$check=$this->model_catalog_cat->checkChildrenMenu($parent_id);
			$getc='cat_id';
			$pathc='cat&amp;paths=';
		}
		if($results){
			if($count>1){
				if(!$check){
					$output .= '<div class="childcontent-inner clearfix" style="width: 620px;">
									<table border=0 >';
					
					for ($i=0;$i<count($results);$i+=3){
						$output .='<tr valign="top">';
						for($j=$i;$j<$i+3;$j++){
							if (!$current_path) {
								$new_path = $results[$j][$getc];
							} else {
								$new_path = $current_path . '_' . $results[$j][$getc];
							}
							$output .='<td><div class="megacol" style="width: 200px;">
										<ul class="megamenu level1"><li class="mega first group"><div class="group">
										<div class="group-title"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path)  . '" class="mega first group" ><span class="menu-title">'. $results[$j]['name'] .'</span></a></div>
										<div class="group-content">
										<ul class="megamenu level1">';
							if($category=='category'){		
								$childresults = $this->model_catalog_category->getCategories($results[$j][$getc]);
							}else{
								$childresults = $this->model_catalog_cat->getCats($results[$j][$getc]);
							}
							
							if($childresults){
							//$current_path=$new_path;
								for ($k=0;$k<count($childresults);$k++){
									if (!$current_path) {
										$new_path2 = $childresults[$k][$getc];
									} else {
										$new_path2 = $current_path . '_' . $childresults[$k][$getc];
									}
									if($k==0){
										$output.='<li class="mega first"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path2)  . '" class="mega first" ><span class="menu-title">' . $childresults[$k]['name'].$count . '</span></a>';
									}else if($k==count($childresults)-1){
										$output.='<li class="mega last"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path2)  . '" class="mega last" ><span class="menu-title">' . $childresults[$k]['name'] . '</span></a>';
									}else{
										$output.='<li class="mega"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path2)  . '" class="mega" ><span class="menu-title">' . $childresults[$k]['name'] . '</span></a>';
									}
									
									$output.='</li>';
											
									
								}
								$output .='</ul></div></div></li></ul></div></div></td>';
							}
							
						}	
						$output .='	</tr>';
					}
					$output .='	</table></div>';
				}else{
						$output .= '<div class="childcontent-inner clearfix" style="width: 200px;">
									<div class="megacol column1" style="width: 200px;">
									<ul class="megamenu level1">';
						for($j=0;$j<count($results);$j++){
							if($j==0){
								$css='first';
							}else if($j==count($results)-1){
								$css='last';
							}else{
								$css='';
							}
							if (!$current_path) {
								$new_path = $results[$j][$getc];
							} else {
								$new_path = $current_path . '_' . $results[$j][$getc];
							}
							if($category=='category'){		
								$childresults = $this->model_catalog_category->getCategories($results[$j][$getc]);
							}else{
								$childresults = $this->model_catalog_cat->getCats($results[$j][$getc]);
							}
							
							if($childresults){
							//$current_path=$new_path;
								$output .='	<li class="mega '.$css.' haschild"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path)  . '" class="mega first group" ><span class="menu-title">'. $results[$j]['name'] .'</span></a>
										 	<div class="childcontent cols1 ">
									        <div class="childcontent-inner-wrap">
									        <div class="top" ><div class="tl"></div><div class="tr"></div></div>
									        <div class="mid">
									        <div class="ml"></div>
									        <div class="childcontent-inner clearfix" style="width: 200px;"><div class="megacol column1" style="width: 200px;">
									        <ul class="megamenu level2">';
								for ($k=0;$k<count($childresults);$k++){
									if (!$current_path) {
										$new_path2 = $childresults[$k][$getc];
									} else {
										$new_path2 = $current_path . '_' . $childresults[$k][$getc];
									}
									if($k==0){
										$output.='<li class="mega first"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path2)  . '" class="mega first" ><span class="menu-title">' . $childresults[$k]['name'].$count . '</span></a>';
									}else if($k==count($childresults)-1){
										$output.='<li class="mega last"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path2)  . '" class="mega last" ><span class="menu-title">' . $childresults[$k]['name'] . '</span></a>';
									}else{
										$output.='<li class="mega"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path2)  . '" class="mega" ><span class="menu-title">' . $childresults[$k]['name'] . '</span></a>';
									}
									
									$output.='</li>';
											
									
								}
								$output .= '</ul></div></div>
											<div class="mr"></div>
									        </div><div class="bot" ><div class="bl"></div><div class="br"></div></div>
									        </div></div></li>';
							}else{
								$output.='<li class="mega '.$css.'"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path)  . '" class="mega first group" ><span class="menu-title">'. $results[$j]['name'] .'</span></a></li>';
							}
							
						}
						$output.='</ul></div></div>';	
				}	
				
			}else{
				$output .= '<div class="childcontent-inner clearfix" style="width: 200px;">
								<div class="megacol column1 first" style="width: 200px;">
									<ul class="megamenu level1">';
				for ($i=0;$i<count($results);$i++){
					if (!$current_path) {
						$new_path = $results[$i][$getc];
					} else {
						$new_path = $current_path . '_' . $results[$i][$getc];
					}
					if($i==0){
						$output.='<li class="mega first"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path)  . '" class="mega first" ><span class="menu-title">' . $results[$i]['name'] . '</span></a>';
					}else if($i==count($results)-1){
						$output.='<li class="mega last"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path)  . '" class="mega last" ><span class="menu-title">' . $results[$i]['name'] . '</span></a>';
					}else{
						$output.='<li class="mega"><a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/'.$pathc. $new_path)  . '" class="mega" ><span class="menu-title">' . $results[$i]['name'] . '</span></a>';
					}
					
					$output.='</li>';
							
					
				}
				$output.='</ul></div></div>';
			}
		}
		
		return $output;
		//<div class="childcontent-inner clearfix" style="width: 200px;"><div class="megacol column1 first" style="width: 200px;"><ul class="megamenu level1"><li class="mega first"><a href="@ja_menu=split" class="mega first" id="menu59" title="Split menu"><span class="menu-title">Split menu</span></a></li><li class="mega"><a href="@ja_menu=css" class="mega" id="menu61" title="CSS menu"><span class="menu-title">CSS menu</span></a></li><li class="mega"><a href="@ja_menu=dropline" class="mega" id="menu63" title="Dropline menu"><span class="menu-title">Dropline menu</span></a></li><li class="mega last"><a href="@ja_menu=mega" class="mega last" id="menu60" title="Mega menu"><span class="menu-title">Mega menu</span></a></li></ul></div></div>
	}
	protected function getCategories3($parent_id, $current_path = ''){
		$cat_id = array_shift($this->path);		
		$output='<div class="childcontent-inner clearfix" style="width: 200px;">
					<table border=0>';	
		$results = $this->model_catalog_cat->getCats($parent_id);
		if ($results) { 
			if($parent_id!=0){				
				$output .= '<ul class="sub-menu">';
			}
    	}   	
		foreach ($results as $result) {	
			if (!$current_path) {
				$new_path = $result['cat_id'];
			} else {
				$new_path = $current_path . '_' . $result['cat_id'];
			}
			
			$output .= '<li class="menu-item">';
			
			$children = '';
			
			if ($cat_id != $result['cat_id']) {
				$children = $this->getCategories3($result['cat_id'], $new_path);
			}
			
			//if ($this->category_id == $result['category_id']) {
				$output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/cat&amp;path=' . $new_path)  . '"><span>' . $result['name'] . '</span></a>';
			//} else {
			//	$output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&amp;path=' . $new_path)  . '">' . $result['name'] . '</a>';
			//}
			
        	$output .= $children;
        
        	$output .= '</li>'; 
		}
		if ($results) {
		if($parent_id!=0){				
				$output .= '</ul>';
			}
		}
		return $output;
	}
	public function city() {
		$output = '';
		
		$this->load->model('localisation/city');
		
		$results = $this->model_localisation_city->getCitysByZoneId($this->request->get['zone_id']);
		
		foreach ($results as $result) {
			$output .= '<option value="' . $result['city_id'] . '"';

			if (isset($this->request->get['city_id']) && ($this->request->get['city_id'] == $result['city_id'])) {
				$output .= ' selected="selected"';
			}

			$output .= '>' . $result['name'] . '</option>';
		}

		if (!$results) {
			$output .= '<option value="0">' . $this->language->get('text_none') . '</option>';
		}

		$this->response->setOutput($output, $this->config->get('config_compression'));
	}
	public function translateDate($date){
		$strday='';
		$day='';
		
		if(isset($date)){
			$array=split(" ",$date);		
			$day=$array[0];
			$date=$array[1];
			if(isset($day)){
				switch ($day){
					case "Monday":
						$strday='Thứ Hai';
						break;
					case "Tuesday":
						$strday='Thứ Ba';
						break;
					case "Wednesday":
						$strday='Thứ Tư';
						break;
					case "‎Thursday":
						$strday='Thứ Năm';
						break;
					case "Friday":
						$strday='Thứ Sáu';
						break;
					case "Saturday":
						$strday='Thứ Bảy';
						break;
					case "Sunday":
						$strday='Chủ Nhật';
						break;	
				}
			}
		}
		return $strday." ".$date;
	}
}
?>